#include <graphics.h>
#include "DeclareFile.h"


#define     VK_A	65
#define 	VK_S	83
#define 	VK_D	68
#define 	VK_W	87
#define 	VK_J	74
#define 	VK_K	75
#define 	VK_L	76
#define 	VK_I	73


void MOUSE_Key_Eevent() {

	//FlushMouseMsgBuffer();
	ExMessage msg;
	peekmessage(&msg, EX_MOUSE);
	if (msg.message == WM_LBUTTONDOWN) {

		//peekmessage(&msg, EX_MOUSE);
		//if (msg.message == WM_LBUTTONUP) {

		int x = msg.x;
		int y = msg.y;

		//如果此时是在菜单界面
		if (flag == 1) {


			//如果点击的是开始游戏
			if (x >= x_ + hSpace && x_ <= x + hSpace + textwidth("开始游戏")
				&& y >= y_ + 60 + vSpace && y <= y_ + 60 + vSpace + textheight("开始游戏")) {

				cleardevice();
				flag = 3;
				return;
			}
			else if (x >= x_ + hSpace && x <= x_ + hSpace + textwidth("游戏设置")
				&& y >= y_ + 60 * 2 + vSpace && y <= y_ + 60 * 2 + vSpace + textheight("游戏设置")) {//如果点击的是设置游戏
				setbkcolor(WHITE);
				cleardevice();
				flag = 6;
				return;
			}
			else if (x >= x_ + hSpace && x <= x_ + hSpace + textwidth("退出游戏")
				&& y >= y_ + 60 * 3 + vSpace && y <= y_ + 60 * 3 + vSpace + textheight("退出游戏")) {//如果点击的是退出游戏
				flag = 5;
				return;
			}
			else if (x >= x_ - 290 && x <= x_ - 290 + textwidth("排行榜")
				&& y >= 530 && y <= 530 + textheight("排行榜")) {//如果点击的是排行榜
				flag = 4;
				cleardevice();
				return;
			}
		}

			else if (flag == 3) {  //此时在游戏界面

				//点击的位置在暂停按钮上
				if (x >= 680 && x <= 780 && y >= 20 && y <= 60) {
					flag = 2;
					return;
				}

			}
			else if (flag == 2) { // 如果此时在暂停界面

				if (x >= BUTTON_X && x <= BUTTON_X + BUTTON_WIDTH
					&& y >= BUTTON_Y_1 && y <= BUTTON_Y_1 + BUTTON_HEIGHT) {
					//如果在暂停界面点击继续按钮
					flag = 3;
					setbkcolor(BLACK);
					cleardevice();
					return;
				}
				else if (x >= BUTTON_X && x <= BUTTON_X + BUTTON_WIDTH
					&& y >= BUTTON_Y_2 && y <= BUTTON_Y_2 + BUTTON_HEIGHT) {
					//如果在暂停界面点击设置按钮

					//此时有一条路径  游戏界面 -> 暂停 ->设置是存在的, 为true
					GAME_PAUSE_SET = true;
					cleardevice();
					flag = 6;
					return;
				}
				else if (x >= BUTTON_X && x <= BUTTON_X + BUTTON_WIDTH
					&& y >= BUTTON_Y_3 && y <= BUTTON_Y_3 + BUTTON_HEIGHT) {
					//如果在暂停界面点击退出游戏按钮
					exit(0);
				}

			}
			//else if (flag == 6) {//如果此时在设置界面

			//	//如果点击的是增大
			//	if (x >= rx1 && x <= rx_w1 && y >= ry1 && y <= ry_h1) {
			//		if (MusicSizeNumber < 100) {
			//				MusicSizeNumber++;
			//			return;
			//		}
			//	}
			//	else if (x >= rx2 && x <= rx_w2 && y >= ry2 && y <= ry_h2) {//如果点击的是减小
			//		if (MusicSizeNumber > 0) {
			//				MusicSizeNumber--;
			//			return;
			//		}
			//	}
			//	else if (x >= BUTTON_X && x <= BUTTON_X + BUTTON_WIDTH && y >= BUTTON_Y_3 && y <= BUTTON_Y_3 + BUTTON_Y_3 + BUTTON_HEIGHT) {
			//		//如果点击的是返回按钮
			//		flag = 2;
			//		GAME_PAUSE_SET = false;
			//		//cleardevice();
			//		return;
			//	}


			//}
			else if (flag == 7) {

				//如果此时在游戏结算画面
			}
			//}
		}






		if (GetAsyncKeyState(VK_W) & 0x8000 && flag == 3 && ControlValOne <= 0) {//表示在游戏界面按下w键

			//控制人物向上移动

			imgY -= 1;
			ControlValOne = 20;
			HeroShowIndex = 8;
		}
		else if (GetAsyncKeyState(VK_A) & 0x8000 && flag == 3 && ControlValOne <= 0) {//此时按下的是向左移动

			imgX -= 1;
			ControlValOne = 20;
			HeroShowIndex = 4;
		}
		else if (GetAsyncKeyState(VK_D) & 0x8000 && flag == 3 && ControlValOne <= 0) { //此时按下的是向右移动
			imgX += 1;
			ControlValOne = 20;
			HeroShowIndex = 6;
		}
		else if (GetAsyncKeyState(VK_S) & 0x8000 && flag == 3 && ControlValOne <= 0) { //此时按下的是向下移动
			imgY += 1;
			ControlValOne = 20;
			HeroShowIndex = 2;
		}
		else if (GetAsyncKeyState(VK_J) & 0x8000 && flag == 3 && ControlAttack1 <= 0) {
			ControlAttack1 = 20;
			ControlValOne = 20;
			HeroShowIndex = 1;
		}
		else if (GetAsyncKeyState(VK_K) & 0x8000 && flag == 3 && ControlAttack2 <= 0) {
			ControlAttack2 = 20;
			ControlValOne = 20;
			HeroShowIndex = 3;
		}
		else if (GetAsyncKeyState(VK_L) & 0x8000 && flag == 3 && ControlAttack3 <= 0) {
			ControlAttack3 = 20;
			ControlValOne = 20;
			HeroShowIndex = 5;
		}
		else if (GetAsyncKeyState(VK_I) & 0x8000 && flag == 3 && ControlAttack4 <= 0) {
			ControlAttack4 = 20;
			ControlValOne = 20;
			HeroShowIndex = 7;
		}


}